package ar.uba.fi.algo3.java2d.ejemplo4;

import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.Dimension;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Color;

public class VentanaPrincipal extends Frame {

	private static final long serialVersionUID = 1L;
	private Panel panel = null;
	private Panel panelInfo = null;
	private Label labelX = null;
	private TextField textFieldX = null;
	private Label labelY = null;
	private TextField textFieldY = null;
	/**
	 * This method initializes panelMutante	
	 * 	
	 * @return java.awt.Panel	
	 */
	private Panel getPanelMutante() {
		if (panel == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
			panel = new Panel();
			panel.setLayout(flowLayout);
			panel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
				public void mouseMoved(java.awt.event.MouseEvent e) {
					System.out.println("mouseClicked(" + e.getX() + "," + e.getY() + ")");
					textFieldX.setText(String.valueOf(e.getX()));
					textFieldY.setText(String.valueOf(e.getY()));
				}
			});
		}
		return panel;
	}

	/**
	 * This method initializes panelInfo	
	 * 	
	 * @return java.awt.Panel	
	 */
	private Panel getPanelInfo() {
		if (panelInfo == null) {
			labelY = new Label();
			labelY.setText("Y:");
			labelX = new Label();
			labelX.setText("X:");
			panelInfo = new Panel();
			panelInfo.setLayout(new FlowLayout());
			panelInfo.setMinimumSize(new Dimension(30, 30));
			panelInfo.setPreferredSize(new Dimension(30, 30));
			panelInfo.setBackground(Color.lightGray);
			panelInfo.add(labelX, null);
			panelInfo.add(getTextFieldX(), null);
			panelInfo.add(labelY, null);
			panelInfo.add(getTextFieldY(), null);
		}
		return panelInfo;
	}

	/**
	 * This method initializes textFieldX	
	 * 	
	 * @return java.awt.TextField	
	 */
	private TextField getTextFieldX() {
		if (textFieldX == null) {
			textFieldX = new TextField();
			textFieldX.setMinimumSize(new Dimension(35, 23));
			textFieldX.setPreferredSize(new Dimension(35, 23));
		}
		return textFieldX;
	}

	/**
	 * This method initializes textFieldY	
	 * 	
	 * @return java.awt.TextField	
	 */
	private TextField getTextFieldY() {
		if (textFieldY == null) {
			textFieldY = new TextField();
			textFieldY.setMinimumSize(new Dimension(35, 23));
			textFieldY.setPreferredSize(new Dimension(35, 23));
		}
		return textFieldY;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		VentanaPrincipal ventana = new VentanaPrincipal();
		ventana.setVisible(true);
	}

	/**
	 * This is the default constructor
	 */
	public VentanaPrincipal() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setTitle("Java2D - Ejemplo 4");
		//this.setLayout(new GridLayout.)
		this.add(getPanelMutante(), BorderLayout.CENTER);
		this.add(getPanelInfo(), BorderLayout.SOUTH);
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				System.out.println("windowClosing()");
				System.exit(NORMAL);
			}
		});
	}

}
